#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
using namespace std;
class Solution {
public:
    string decode(string& s, int& pos)
    {
        string tmp;
        while (pos < s.size())
        {
            if (isdigit(s[pos]))
            {
                int num = s[pos] - '0';
                while (isdigit(s[pos + 1]))
                {
                    num *= 10;num += s[pos + 1] - '0';
                    pos++;
                }
                string tmp_;
                pos += 2;
                tmp_ = decode(s, pos);
                for (int i = 0;i <num;i++)
                    tmp += tmp_;
            }
            else if (isalpha(s[pos]))
            {
                tmp += s[pos];
                pos++;
            }
            else if (s[pos] == ']')
            {
                pos++;
                return tmp;
            }
        }
        return tmp;
    }
    string decodeString(string s)
    {
        int pos = 0;
        return decode(s, pos);
    }
};
int main()
{
    string s = "100[leetcode]";
    cout<<Solution().decodeString(s);
    
	return 0;
}